package manage.action;

import m.common.action.ActionMeta;
import m.common.action.VueResult;
import m.html.VueFormResult;
import m.html.element.Button;
import m.html.element.Element;
import m.html.element.attr.ButtonType;
import m.html.form.*;
import m.system.exception.MException;
import m.system.util.JSONMessage;
import manage.model.SystemInfo;
import manage.service.SystemInfoService;

@ActionMeta(name="manage/systemInfo")
public class SystemInfoAction extends ManageAction {
	private SystemInfo model;
	
	public JSONMessage get() throws MException {
		return new JSONMessage(0)
				.push("model", getService(SystemInfoService.class).getUniqueModel());
	}
	
	public JSONMessage doSave() throws Exception {
		systemLog("系统信息","保存系统信息");
		verifyAdminOperPower("manage_system_power");
		String msg=getService(SystemInfoService.class).save(model);
		return new JSONMessage(0,msg);
	}
	public VueResult toEdit() throws Exception {
		verifyMenu("A1107");
		verifyAdminOperPower("manage_system_power");

		ModelForm form = new ModelForm("系统信息",4);
		form.addItem(
			FormInput.input("后台标题", "model.backgroundTitle").setPlaceholder("请输入后台标题").setRequired(true).setSpan(2),
			FormInput.select("标题模式", "model.titleType", "manage.model.SystemInfo!titleType").setPlaceholder("请选择后台显示类型"),
			FormInput.selectIcon("标题图标", "model","titleIcon"),
			FormInput.input("网站域名", "model.domainName").setPlaceholder("请输入域名").setSpan(2),
			FormInput.select("背景模式", "model.backgroundType", "manage.model.SystemInfo!backgroundType").setPlaceholder("请选择登录背景"),
			FormInput.selectImage("背景图片", "model", "backgroundImage","backgroundImage"),
			FormInput.input("静态域名地址", "model.staticDomain").setPlaceholder("请输入静态域名地址").setSpan(2),
			FormInput.select("静态加速模式", "model.staticMode", "manage.model.SystemInfo!staticMode").setPlaceholder("请选择静态加速模式"),
			FormInput.radio("外协登录", "model.assistLogin", "manage.model.SystemInfo!assistLogin"),
			FormHtml.ins("颜色设置","<a-flex :gap=\"8\" align=\"center\">"
				+"主题:<input type=\"color\" v-model=\"model.primaryColor\"/>"
				+"成功:<input type=\"color\" v-model=\"model.successColor\"/>"
				+"警戒:<input type=\"color\" v-model=\"model.warningColor\"/>"
				+"错误:<input type=\"color\" v-model=\"model.errorColor\"/>"
				+"信息:<input type=\"color\" v-model=\"model.infoColor\"/>"
			+"</a-flex>").setSpan(2),
			FormInput.radio("Form模式", "model.formMode", "manage.model.SystemInfo!formMode").setSpan(2),
			FormHtml.ins("边角风格","<a-slider v-model:value=\"model.borderRadius\" :marks=\"marks\" :min=\"1\" :max=\"16\">").setSpan(2),
			FormInput.radio("图片压缩", "model.imageMode", "manage.model.SystemInfo!imageMode").setSpan(2)
		)
		.addData("model",getService(SystemInfoService.class).getUniqueModel())
		.addData("marks",new JSONMessage().push("3","默认").push("8","圆角"))
		.addButton(
			FormButton.pri("保存","doSave")
		)
		.addMethod(
			FormEvent.backTrue,
			FormEvent.doJson("doSave",actionUrl("doSave"),"{model:this.model}")
				.success("backTrue")
		);
		CustomForm customForm=new CustomForm("资源管理").setSubTitle("管理静态资源")
			.addElement(Element.tag("a-space").A("style","padding:15px;").E(
				new Button(ButtonType.PRIMARY).E("图片管理").setExtend("@click=\"imageInfoList\""),
				new Button(ButtonType.PRIMARY).E("图标管理").setExtend("@click=\"iconManage\""),
				new Button(ButtonType.PRIMARY).E("ICON查看").setExtend("@click=\"viewIconClass\""),
				new Button(ButtonType.PRIMARY).E("用户列管理").setExtend("@click=\"adminColumnManage\"")
			))
			.addMethod(
				FormEvent.toModal("imageInfoList",actionUrl(ImageInfoAction.class,"imageInfoList"),"{}",1000),
				FormEvent.toModal("iconManage","page/base/util/iconManage.js","{}",1000),
				FormEvent.toModal("viewIconClass","page/base/util/viewIconClass.js","{}",1000),
				FormEvent.toModal("adminColumnManage",actionUrl(AdminColumnAction.class,"allList"),"{}",1000)
			);
		LoadPage filePage=new LoadPage("loadUploadFilePage","page/base/util/busiFile.js","{title:'升级文件',fileType:'updateJar',businessOid:this.model.oid,oper:'edit'}")
			.setMounted("this.loadUploadFilePage();");
		LoadPage hostPage=new LoadPage("loadHostPage","page/base/host/hostList.js","{}")
			.setMounted("this.loadHostPage();");
		VueFormResult result=new VueFormResult();
		return result.addForm(form).addForm(customForm).addForm(filePage).addForm(hostPage);
	}


	public SystemInfo getModel() {
		return model;
	}

	public void setModel(SystemInfo model) {
		this.model = model;
	}


}
